package gates;

import gates.Gate;
import register.Register;

/**
 * Creates a gate that is a composition of two or more gates.
 * @author Matt Cole, Alex Bush
 */
public class CompositeGate implements Gate {

	/** Store the array of gates creating the composition */
	private Gate[] gates;
	
	/**
	 * Protected constructor to create a composite gate object. Use the <code>Factory</code> class to create
	 * an instance of this object.
	 * @param gates
	 */
	protected CompositeGate(Gate[] gates){
		this.gates = gates;
	}
	
	/**
	 * Apply this gate to a given register. Will cycle through all the gates in the array
	 * and apply them sequentially.
	 */
	public void apply(Register r) {
		for (int i = 0; i < gates.length; i++){
			gates[i].apply(r);
		}
	}

	/** Return the name of this gate */
	public String getName(){
		return "Composite";
	}

	/** Return where this gate is functional or not.
	 * As this is a composition that can contain both, it is kind of a null question.
	 * Just return false
	 */
	public boolean isFunctional() {
		return false;
	}

}